package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.QueryAlhHistoryProductsBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.QueryAlhHistoryProductsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*查询安利会历史商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryAlhHistoryProducts{
	private static QueryAlhHistoryProductsBean queryalhhistoryproductsBean;
	private static QueryAlhHistoryProductsCall queryalhhistoryproductsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询安利会历史商品列表");
	}

	@Before
	public void caseUp() {
		queryalhhistoryproductsBean=new QueryAlhHistoryProductsBean();
		queryalhhistoryproductsCall=new QueryAlhHistoryProductsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryalhhistoryproductsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryAlhHistoryProducts_001() {
		Logger.start(true,"推广然后停止推广,成功查询到");
		try {
			
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			
			ProductManagerCallServiceV3.BatchAddAlhProduct(sellerId, productId);
			ProductManagerCallServiceV3.BatchStopAlhProduct(sellerId, productId);
			queryalhhistoryproductsBean.setUserId(sellerId);
			queryalhhistoryproductsBean.setPageIndex(1);
			queryalhhistoryproductsBean.setPageSize(100);
			queryalhhistoryproductsCall.setData(queryalhhistoryproductsBean);
			queryalhhistoryproductsCall.callService();			
			Logger.verifyEquals("200", queryalhhistoryproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, queryalhhistoryproductsCall.getJsonObject().toString().indexOf(productId), "");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryAlhHistoryProducts_002() {
		Logger.start(true,"停止推广，开启推广好多次,成功查询到");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			
			for (int i = 0; i < 10; i++) {
				ProductManagerCallServiceV3.BatchAddAlhProduct(sellerId, productId);
				ProductManagerCallServiceV3.BatchStopAlhProduct(sellerId, productId);
			}	
			queryalhhistoryproductsBean.setUserId(sellerId);
			queryalhhistoryproductsBean.setPageIndex(1);
			queryalhhistoryproductsBean.setPageSize(100);
			queryalhhistoryproductsCall.setData(queryalhhistoryproductsBean);
			queryalhhistoryproductsCall.callService();			
			Logger.verifyEquals("200", queryalhhistoryproductsCall.getJsonObject().get("Code").getAsString(), "验证Code");
			Logger.verifyNotEquals(-1, queryalhhistoryproductsCall.getJsonObject().toString().indexOf(productId), "");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryAlhHistoryProducts_003() {
		Logger.start(true,"部分商品消息未完善,查询成功");
		try {
			
			
			queryalhhistoryproductsCall.setData(queryalhhistoryproductsBean);
			queryalhhistoryproductsCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}